/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uit.tkorg.coauthorgraph.servlet.graph;

import edu.uci.ics.jung.graph.UndirectedSparseGraph;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import uit.tkorg.coauthorgraph.bo.AuthorPaperBO;
import uit.tkorg.coauthorgraph.bo.CoAuthorGraphBO;
import uit.tkorg.coauthorgraph.bo.ConferenceBO;
import uit.tkorg.coauthorgraph.bo.JournalBO;
import uit.tkorg.coauthorgraph.graph.CoAuthorGraphVertex;
import uit.tkorg.coauthorgraph.utility.HashMapUtility;

/**
 *
 * @author Tin Huynh
 */
public class CalculateTotalConferenceServlet extends HttpServlet {

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            System.out.println("************************************************************");
            System.out.println("------------Calculate Metrics: #1. Total Conference-------");
            HttpSession session = request.getSession();
            UndirectedSparseGraph graph = (UndirectedSparseGraph) session.getAttribute("coAuthorGraph");
            CoAuthorGraphBO coAuthorGraphBO = new CoAuthorGraphBO();
            ArrayList authorVertexIDList = coAuthorGraphBO.getAuthorVertexIDListInGraph(graph);
            AuthorPaperBO authorPaperBO = new AuthorPaperBO();
            ConferenceBO confBO = new ConferenceBO();
            HashMap confPaperCountHashMap = authorPaperBO.getTotalPaperInEachConfOfAuthorList(authorVertexIDList);
            confPaperCountHashMap = (HashMap) HashMapUtility.getSortedMapDescending(confPaperCountHashMap);
            request.setAttribute("confPaperCountHashMap", confPaperCountHashMap);
            JournalBO jourBO = new JournalBO();
            HashMap jourPaperCountHashMap = authorPaperBO.getTotalPaperInEachJourOfAuthorList(authorVertexIDList);
            jourPaperCountHashMap = (HashMap) HashMapUtility.getSortedMapDescending(jourPaperCountHashMap);
            request.setAttribute("jourPaperCountHashMap", jourPaperCountHashMap);

            RequestDispatcher dispatcher = request.getRequestDispatcher("./jsp/MetricsTotalConference.jsp");
            dispatcher.forward(request, response);
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
